package com.gaofeng.day22.a10ThreadDemo;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
public class MyThread extends Thread{
    static Object objA = new Object();
    static Object objB = new Object();
    @Override
    public void run() {
        while (true){
            if("线程A".equals(getName())){
                synchronized (objA){
                    System.out.println("线程A拿到了A锁");
                    synchronized (objB){
                        System.out.println("线程A拿到了B锁");
                    }
                }
            }else if("线程B".equals(getName())){
                if("线程B".equals(getName())){
                    synchronized (objB){
                        System.out.println("线程B拿到了A锁");
                        synchronized (objA){
                            System.out.println("线程B拿到了A锁");
                        }
                    }
                }
            }
        }
    }
}